package action.system;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.PageContext;

import org.apache.struts2.ServletActionContext;
import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;

import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

import action.BaseAction;
import common.StringHelper;
import domain.entity.SysMenu;
import service.system.MenuService;
@ParentPackage("authorityInterceptor")
public class MenuAction extends BaseAction {
	private List<SysMenu> menus = new ArrayList<SysMenu>();

	HttpSession session = ServletActionContext.getRequest().getSession();
	public String LoadChildMenuByParent() {
		String id=request.getParameter("id").toString() ;
		if (StringHelper.isNullOrWhiteSpace(id))
			id = "1";
		Map<String, String> ca = (Map<String, String>) session.getAttribute("ControllerActions");
		List<SysMenu> menus = MenuService.getChildMenuByParent(id, ca);
		context.setAttribute("menus", menus);
		return SUCCESS;
	}

	//@Action(value = "LoadTopMenu", results = { @Result(name = "success", location = "/Views/System/Menu/TopMenu.jsp") })
	public String LoadTopMenu() {
		Object o=request.getParameter("id");
		int id=Integer.parseInt(o.toString()) ;
		context.setAttribute("TopMenuID", id);
		List<SysMenu> menus = MenuService.getChildMenuByParent(null, null);
		context.setAttribute("menus", menus);
		return SUCCESS;
	}
}
